package com.hmall.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {
    @Bean
    public ExecutorService executorService(ThreadPoolProperties pool) {
        System.out.println("pool = " + pool);
        return new ThreadPoolExecutor(
                pool.getCorePoolSize(),
                pool.maximumPoolSize,
                pool.getKeepAlive(),
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(pool.getQueue()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}
